<template>
  <span
    v-if="$settings.consoleUrl && $getLoginUser().consoleType == '0'"
    class="noticeButton ant-dropdown-trigger ant-pro-dropdown ant-pro-dropdown-action action"
  >
    <avic-icon class="anticon icon" style="font-size: 1.25em" title="返回控制台" svg="avic-computer-fill" @click="handleToConsole" />
  </span>
</template>
<script lang="ts" setup>
import { TENANT_ID } from '@/store/user';
import { getToken, getCookie } from '@/utils/common-util';
const { proxy } = getCurrentInstance();
defineProps({
  currentUser: {
    type: Object,
    default: () => null
  }
});
function handleToConsole() {
  window.name = 'portal';
  const token = getToken();
  let { consoleUrl } = proxy.$settings;
  consoleUrl = consoleUrl.endsWith('/') ? consoleUrl : `${consoleUrl}/`;
  const tenantId = getCookie(TENANT_ID);
  const tenantSearchParam = tenantId ? `&tenantId=${tenantId}` : '';
  window.open(`${consoleUrl}access-from-portal?access_token=${token}&redirect_url=/backstage${tenantSearchParam}`, 'console');
}
</script>

<style lang="less" scoped></style>
